package com.tingyuge.thinking.spring.configuration.bean.lifecycle;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
import org.springframework.util.ObjectUtils;

/**
 * @author xiaodao
 * @version 1.0
 * @date 2021/7/11
 */
public class MyDestructionAwareBeanPostProcessor implements DestructionAwareBeanPostProcessor {
    @Override
    public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException {
        if (ObjectUtils.nullSafeEquals("userHolder", beanName) && UserHolder.class.equals(bean.getClass())) {
            UserHolder userHolder = (UserHolder)bean;
            //postProcessAfterInitialization v8---v9>
            // userHolder description = the userHolder is v9
            userHolder.setDescription("the userHolder is v9");
            System.out.println("(postProcessBeforeDestruction): " +"the userHolder is v9");
        }
    }
}
